package algorithm;

import java.util.Arrays;

/**
 * @author zhangxin
 * @date 2021/4/29
 */
public class MergeArray {

    public static void main(String[] args) {

        int[] arr1 = new int[]{1, 3, 5, 7, 9};

        int[] arr2 = new int[]{2, 2, 4, 6, 8, 10};


        int[] newArray = new int[arr1.length + arr2.length];


        int p1 = 0, p2 = 0;

        int x = 5;
        x = ++x + x++;

        System.out.println(x);
        int currentValue = 0;
        while (p1 < arr1.length || p2 < arr2.length) {
            if (p1 == arr1.length) {
                currentValue = arr2[p2++];
            } else if (p2 == arr2.length) {
                currentValue = arr1[p1++];
            } else if (arr1[p1] < arr2[p2]) {
                currentValue = arr1[p1++];
            } else {
                currentValue = arr2[p2++];
            }

            newArray[p1 + p2 - 1] = currentValue;
        }


        System.out.println(Arrays.toString(newArray));
    }
}
